<template>
  <el-form ref="formRef" style="max-width: 500px" :inline="true" :model="formInline" class="demo-form-inline">
    <el-form-item label="公告标题：" prop="title" :rules="[{
      required: true,
      message: '请输入公告标题',
      trigger: 'blur'
    }]">
      <el-input v-model="formInline.title" placeholder="请输入公告标题" clearable />
    </el-form-item>
    <el-form-item label="公告内容：" prop="content" :rules="[{
      required: true,
      message: '请输入公告内容',
      trigger: 'blur'
    }]"
    class="w-full ">
      <el-input v-model="formInline.content" placeholder="请输入公告内容" type="textarea" :autosize="{ minRows: 5 }"/>
    </el-form-item>
    <div>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(formRef)">提交</el-button>
      </el-form-item>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { ApiPost } from '@/utils/Axios';
import { ElNotification, FormInstance } from 'element-plus'
import { reactive, ref } from 'vue'
const formRef = ref<FormInstance>()
const formInline = reactive({
  title: '',
  content: ''
})

const onSubmit = (formEl: FormInstance | undefined) => {
  formEl.validate(val => {
    if (val) {
      ApiPost('/noticeInf/add', formInline).then(res => {
        console.log(res)
        if (res.code === 200) {
          ElNotification({
            title: '添加成功',
            type: 'success',
            duration: 2000,
            showClose: false
          })
        } else {
          ElNotification({
            title: '添加失败',
            message: res.msg,
            type: 'error',
            duration: 2000,
            showClose: false
          })
        }
      }).catch(err => {
        console.log(err)
      })
    }
  })
}
</script>

<style></style>